/**
 * Copyright (C) 2010 altuure <altuure [AT] gmail [DOT] com> http://www.altuure.com/projects/yagdao
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.altuure.yablog.dao;

import java.util.Date;
import java.util.List;

import com.altuure.yablog.model.Category;
import com.altuure.yablog.model.Post;
import com.altuure.yagdao.*;

@YFetch("category")
public interface PostDAO extends GenericDAO<Post, Long> {
    @YMethod(type = YMethodType.SAVE)
    Post create(@YParameter("title") String title,
                @YParameter("body") String body,
                @YParameter("publishDate") Date publishDate,@YParameter("category") Category category);

    @YMethod(type = YMethodType.QUERY,query = "select month(p.publishDate) ,year(p.publishDate),count(p.id)as  nn  from Post p group by month(p.publishDate),year(p.publishDate) order by year(p.publishDate) desc,month(p.publishDate)  desc ")
    SearchResultList listbyDate();

    @YMethod(type = YMethodType.QUERY,queryName = "posts.bymonth")
    SearchResultList listByMonth(@YParameter("year") int year,@YParameter("month")int month,YPage yPage);

    @YMethod(type = YMethodType.QUERY,queryName = "posts.byyear")
    SearchResultList listByYear(@YParameter("year") int year,YPage yPage);

    @YMethod(type = YMethodType.CRITERIA,orderBy = "publishDate desc")
    SearchResultList listTagAndCategory(@YParameter("tags.tag" ) String tag,@YParameter("category.name")String category,YPage yPage);

    @YMethod(type = YMethodType.CRITERIA)
    SearchResultList search(@YParameter(value="body",operator = YOperator.ULIKE) String keyword,YPage yPage);



}
